home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / as400 / tracker / tracker.bas next >
Encoding:
BASIC Source File  |  1995-11-08  |  5.3 KB  |  194 lines

  1. Option Explicit
  2.  
  3.  ' Variables:
  4.   Global gsTrackerDir  As String       ' directory containing tracker
  5.  
  6.   ' data base
  7.   Global dbBackup      As database     ' library backup file
  8.   Global tblBackup     As table        ' library backup info
  9.  
  10. Sub Main ()
  11.  
  12.  ' Description:
  13.  '  The tracker program begins here
  14.  
  15.  ' Variables:
  16.   Dim sTitle As String   ' application title
  17.   
  18.   ' setup global variables
  19.   Call zzSetGlobalVariables
  20.  
  21.   ' please wait...
  22.   Screen.MousePointer = HOURGLASS
  23.  
  24.   ' setup application title
  25.   sTitle = "AS/400 Library Backup Tracker"
  26.   App.Title = sTitle
  27.  
  28.   ' if previous instance of the program running
  29.   ' activate prior instance and end this one
  30.   If App.PrevInstance Then
  31.     
  32.     '...no more waiting
  33.     Screen.MousePointer = DEFAULT
  34.     
  35.     ' clear application title to prevent
  36.     ' this occurance for being invoked
  37.     App.Title = gsEMPTY
  38.  
  39.     ' activate other occurance
  40.     AppActivate sTitle
  41.  
  42.     ' end this one
  43.     End
  44.   
  45.   Else
  46.   
  47.     ' program directory will store database
  48.     gsTrackerDir = App.Path
  49.  
  50.     ' create database
  51.     Call zzCreateDBIfNotFound
  52.   
  53.     ' load main form
  54.     Load frmTracker
  55.     
  56.     ' ...no more waiting
  57.     Screen.MousePointer = DEFAULT
  58.     
  59.     ' show the main form
  60.     frmTracker.Show
  61.  
  62.   End If
  63.  
  64. End Sub
  65.  
  66. Sub zzCreateDBIfNotFound ()
  67.  
  68.  ' Description:
  69.  '  Checks for existance of database and gives the
  70.  '  user the option to create it if it does not
  71.  '  exist. If user chooses not to create the database
  72.  '  then will end program.
  73.   
  74.  ' Variables:
  75.   Dim sDataBaseFile     As String          ' database file name
  76.   Dim sDataBaseWork     As String          ' database work file name
  77.   Dim sTimeStampFile    As String          ' date file created or modified
  78.   
  79.   ' object variables
  80.   Dim fld0                As New Field     ' data base field
  81.   Dim fld1                As New Field     '  "
  82.   Dim fld2                As New Field     '  "
  83.   Dim fld3                As New Field     '  "
  84.   Dim fld4                As New Field     '  "
  85.   Dim fld5                As New Field     '  "
  86.   Dim fld6                As New Field     '  "
  87.   Dim idxNewBackup1       As New Index     ' primary index
  88.   Dim idxNewBackup2       As New Index     ' secondary index
  89.   Dim tblNewBackup        As New TableDef  ' table definition
  90.  
  91.   ' setup data base file names
  92.   sDataBaseFile = gsTrackerDir & "\Tracker.MDB"
  93.   sDataBaseWork = gsTrackerDir & "\Tracker.LDB"
  94.   
  95.   ' see if files exist trying to get date and time
  96.   On Error Resume Next
  97.   sTimeStampFile = FileDateTime(sDataBaseFile)
  98.   On Error GoTo 0
  99.  
  100.   ' if file doesn't exist then create database
  101.   If sTimeStampFile = gsEMPTY Then
  102.  
  103.     ' give user option to abort process
  104.     gsMBText = "The TRACKER database does not exist in """
  105.     gsMBText = gsMBText & gsTrackerDir & """. Do you wish to create"
  106.     gsMBText = gsMBText & " the database at this time?"
  107.     gsMBText = gsMBText & " If you select ""No"" TRACKER will end."
  108.     If MsgBox(gsMBText, MB_YESNO Or MB_ICONEXCLAMATION) = IDYES Then
  109.   
  110.       ' get rid of stray .LDB file
  111.       On Error Resume Next
  112.       Kill sDataBaseWork
  113.       On Error GoTo 0
  114.  
  115.       ' create database
  116.       On Error Resume Next
  117.       Set dbBackup = CreateDatabase(sDataBaseFile$, DB_LANG_GENERAL)
  118.       If dbBackup Is Nothing Then
  119.         gsMBText = "Could not create TRACKER database."
  120.         If Err <> 0 Then gsMBText = gsMBText & " " & Error$
  121.         MsgBox gsMBText, MB_ICONSTOP
  122.         End
  123.       End If
  124.       On Error GoTo 0
  125.  
  126.       ' new table name
  127.       tblNewBackup.Name = "Backups"
  128.  
  129.       ' step up each field and append it
  130.       fld0.Name = "System"
  131.       fld0.Type = DB_TEXT
  132.       fld0.Size = 8
  133.       tblNewBackup.Fields.Append fld0
  134.       
  135.       fld1.Name = "Library"
  136.       fld1.Type = DB_TEXT
  137.       fld1.Size = 10
  138.       tblNewBackup.Fields.Append fld1
  139.  
  140.       fld2.Name = "Object"
  141.       fld2.Type = DB_TEXT
  142.       fld2.Size = 10
  143.       tblNewBackup.Fields.Append fld2
  144.  
  145.       fld3.Name = "When"
  146.       fld3.Type = DB_DATE
  147.       tblNewBackup.Fields.Append fld3
  148.       
  149.       fld4.Name = "Command"
  150.       fld4.Type = DB_TEXT
  151.       fld4.Size = 10
  152.       tblNewBackup.Fields.Append fld4
  153.       
  154.       fld5.Name = "Device"
  155.       fld5.Type = DB_TEXT
  156.       fld5.Size = 10
  157.       tblNewBackup.Fields.Append fld5
  158.       
  159.       fld6.Name = "Volumes"
  160.       fld6.Type = DB_TEXT
  161.       fld6.Size = 60
  162.       tblNewBackup.Fields.Append fld6
  163.       
  164.       ' create primary index
  165.       idxNewBackup1.Name = "Primary"
  166.       idxNewBackup1.Fields = "System;Library;Object;-When"
  167.       idxNewBackup1.Primary = True
  168.       tblNewBackup.Indexes.Append idxNewBackup1
  169.  
  170.       ' create secondary index
  171.       idxNewBackup2.Name = "Secondary"
  172.       idxNewBackup2.Fields = "System;Library;Object"
  173.       idxNewBackup2.Primary = False
  174.       tblNewBackup.Indexes.Append idxNewBackup2
  175.  
  176.       ' append new table object to the tabledefs collection
  177.       dbBackup.TableDefs.Append tblNewBackup
  178.  
  179.       ' close the file and tell user every thing ok
  180.       dbBackup.Close
  181.       gsMBText = "TRACKER database created in directory """
  182.       gsMBText = gsMBText & gsTrackerDir & """."
  183.       MsgBox gsMBText, MB_ICONINFORMATION
  184.       
  185.     ' if database not create then cannot continue
  186.     Else
  187.       End
  188.     End If
  189.   
  190.   End If
  191.   
  192. End Sub
  193.  
  194.